home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / JPNL Libraries / AppletFrame.java < prev    next >
Text File  |  1996-04-27  |  2KB  |  76 lines

  1. /*
  2.     ©1996 Peter N Lewis <peter@stairways.com.au>
  3. */
  4.  
  5. package au.com.peter.libraries;
  6.  
  7. // Generic AppletFrame
  8.  
  9. import java.awt.*;
  10. import java.applet.Applet;
  11.  
  12. // Applet to Application Frame window
  13. public class AppletFrame extends Frame {
  14.  
  15.     public static void startApplet(String className, String title, String args[]) {
  16.         Applet a;
  17.         Dimension appletSize;
  18.  
  19.         try {
  20.             // create an instance of your applet class
  21.             a = (Applet) Class.forName(className).newInstance();
  22.         } catch (Exception e) {
  23.             e.printStackTrace();
  24.             return;
  25.         }
  26.         startApplet( a, title, args );
  27.     }
  28.     
  29.     public static void startApplet(Applet a, String title, String args[]) {
  30.         Dimension appletSize;
  31.  
  32.         // initialize the applet
  33.         a.init();
  34.         a.start();
  35.     
  36.         // create new application frame window
  37.         AppletFrame f = new AppletFrame(title);
  38.     
  39.         // add applet to frame window
  40.         f.add("Center", a);
  41.     
  42.         // resize frame window to fit applet
  43.         // assumes that the applet sets its own size
  44.         // otherwise, you should set a specific size here.
  45.         appletSize =  a.size();
  46.         f.pack();
  47.         f.resize(appletSize);
  48.  
  49.         // show the window
  50.         f.show();
  51.     
  52.     }  // end startApplet()
  53.  
  54.  
  55.     // constructor needed to pass window title to class Frame
  56.     public AppletFrame(String name) {
  57.         // call java.awt.Frame(String) constructor
  58.         super(name);
  59.     }
  60.  
  61.     // needed to allow window close
  62.     public boolean handleEvent(Event e) {
  63.         // Window Destroy event
  64.         if (e.id == Event.WINDOW_DESTROY) {
  65.             dispose();
  66.             return true;
  67.         }
  68.         
  69.         // it's good form to let the super class look at any unhandled events
  70.         return super.handleEvent(e);
  71.  
  72.     }  // end handleEvent()
  73.  
  74. }   // end class AppletFrame
  75.  
  76.